package com.huawei.appgallery.wishlist.ui.fragment;

import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.TaskFragment;
import com.huawei.appgallery.foundation.ui.framework.fragment.AppListFragment;
import com.huawei.appgallery.foundation.ui.framework.widget.toolbar.ToolBarIcon;
import com.huawei.appgallery.wishlist.bean.WishDeleteInfo;
import com.huawei.appgallery.wishlist.bean.WishDeleteResBean;
import com.huawei.appgallery.wishlist.control.WishDeleteListAdapter;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import o.azb;
import o.cku;
import o.dce.a;
import o.dce.c;
import o.dce.f;
import o.dce.i;
import o.dce.j;
import o.dch;
import o.dcp;
import o.dcr;
import o.dda;
import o.doo;
import o.ContentManager;
import o.epv;
import o.CollectCheck;
import o.evk;
import o.ewa;

public class WishListDeleteFragment extends AppListFragment implements OnClickListener {
    private View ʳ;
    private View ʴ;
    private WishDeleteListAdapter ʹ = null;
    private LinearLayout ʹॱ;
    private ImageView ʻʻ;
    private View ʻʼ;
    private View ʻʽ;
    private String ʻˊ = "";
    private List<WishDeleteInfo> ʻˋ;
    private String ʼˋ = "";
    private View ʽʻ;
    ToolBarIcon ˊ;
    private ViewGroup ॱॱ;
    ToolBarIcon ᐝ;
    private ToolBarIcon ꜝ;
    private boolean ꜞॱ = true;
    private boolean ꜟॱ = false;
    private List<StringBuffer> ꞌॱ = new ArrayList();
    private RelativeLayout ﹳ;
    private LinearLayout ﹳॱ;
    private int ﹶ = 0;
    private TextView ﹺ;
    private ListView ﾞ = null;
    private int ﾞॱ = 0;
    private LinearLayout ﾟ = null;
    private List<String> ﾟॱ = new ArrayList();

    public void ˏ(Bundle bundle) {
        ॱˋ(true);
        super.ˏ(bundle);
    }

    public void ˋ(Bundle bundle) {
        super.ˋ(bundle);
        if (this.ʻˋ instanceof ArrayList) {
            bundle.putSerializable("wish_delete_id", (ArrayList) this.ʻˋ);
        }
    }

    public View ˋ(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        super.ˋ(layoutInflater, viewGroup, bundle);
        if (!this.ꜟॱ) {
            this.ʻˋ = dda.ॱ().ˎ();
            if (this.ʻˋ == null) {
                this.ʻˋ = new ArrayList();
                if (bundle != null) {
                    Serializable serializable = bundle.getSerializable("wish_delete_id");
                    if (serializable instanceof ArrayList) {
                        this.ʻˋ = (ArrayList) serializable;
                    }
                }
            }
            this.ꜟॱ = true;
        }
        this.ॱॱ = (ViewGroup) layoutInflater.inflate(i.ॱˋ, viewGroup, false);
        ˎ(this.ॱॱ);
        ˋ(this.ॱॱ);
        return this.ॱॱ;
    }

    private void ˎ(ViewGroup viewGroup) {
        int ˊ = epv.ˊ(ॱˊ(), 2);
        this.ﹳॱ = (LinearLayout) viewGroup.findViewById(e.ˊॱ);
        this.ﾟ = (LinearLayout) viewGroup.findViewById(e.ꓸ);
        azb.ˏ(this.ﾟ);
        this.ﹳ = (RelativeLayout) viewGroup.findViewById(e.ॱ);
        azb.ˏ(viewGroup, e.ʿ);
        this.ꜝ = (ToolBarIcon) viewGroup.findViewById(e.ʼ);
        this.ˊ = (ToolBarIcon) viewGroup.findViewById(e.ʻ);
        this.ᐝ = (ToolBarIcon) viewGroup.findViewById(e.ˋॱ);
        ˎ(this.ꜝ, ˊ);
        ˎ(this.ˊ, ˊ);
        ˎ(this.ᐝ, ˊ);
        this.ꜝ.setOnClickListener(this);
        this.ˊ.setOnClickListener(this);
        this.ᐝ.setOnClickListener(this);
        this.ﾞ = (ListView) viewGroup.findViewById(e.ᶥ);
        if (CollectCheck.isEmpty(this.ʻˋ)) {
            this.ﾟ.setVisibility(0);
            this.ﹳ.setVisibility(8);
        }
        this.ʹ = new WishDeleteListAdapter(ॱˋ(), this.ʻˋ);
        this.ﾞ.setAdapter(this.ʹ);
        this.ﾞ.setOnItemClickListener(new OnItemClickListener(this) {
            final /* synthetic */ WishListDeleteFragment ˏ;

            {
                this.ˏ = r1;
            }

            public void onItemClick(AdapterView<?> adapterView, View view, int i, long j) {
                CheckBox checkBox = (CheckBox) view.findViewById(e.ॱˊ);
                checkBox.setChecked(!checkBox.isChecked());
                if (checkBox.isChecked()) {
                    ((WishDeleteInfo) this.ˏ.ʻˋ.get(i)).ˊ(true);
                } else {
                    ((WishDeleteInfo) this.ˏ.ʻˋ.get(i)).ˊ(false);
                }
                this.ˏ.ˎ(this.ˏ.ꜝ);
                this.ˏ.ˊʻ();
            }
        });
    }

    public void ˋ(ViewGroup viewGroup) {
        this.ʳ = viewGroup.findViewById(e.ˍ);
        azb.ˏ(this.ʳ);
        this.ʻʽ = this.ʳ.findViewById(e.ˋᐝ);
        this.ʹॱ = (LinearLayout) viewGroup.findViewById(e.ʾ);
        this.ʹॱ.setOnClickListener(this);
        this.ﹺ = (TextView) viewGroup.findViewById(e.ˎˎ);
        ˊʻ();
        this.ʻʼ = this.ʳ.findViewById(e.ॱˋ);
        this.ʻʻ = (ImageView) this.ʳ.findViewById(e.ͺ);
        this.ʻʼ.setOnClickListener(this);
        this.ʴ = this.ʳ.findViewById(e.ᐝॱ);
        this.ʴ.setOnClickListener(this);
        this.ʽʻ = this.ʳ.findViewById(e.ʼॱ);
        this.ʽʻ.setOnClickListener(this);
        if (2 == ᐝॱ().getConfiguration().orientation) {
            this.ﹳॱ.setVisibility(8);
        } else {
            this.ʻʽ.setVisibility(8);
        }
        ˎ(this.ꜝ);
    }

    private void ˎ(ToolBarIcon toolBarIcon, int i) {
        LayoutParams layoutParams = (LayoutParams) toolBarIcon.getLayoutParams();
        layoutParams.width = i;
        toolBarIcon.setLayoutParams(layoutParams);
    }

    public void ˋ(TaskFragment taskFragment, List list) {
        list.add(new dcr(this.ʻˊ));
    }

    public boolean ˊ(TaskFragment taskFragment, b bVar) {
        WishDeleteResBean wishDeleteResBean = (WishDeleteResBean) bVar.ˋ;
        if (!doo.ˊ(ॱˊ())) {
            evk.ˏ(ॱ(j.ˋ));
        } else if (wishDeleteResBean.getResponseCode() == 0 && wishDeleteResBean.getRtnCode_() == 0) {
            new dcp().ॱ();
            this.ﾞॱ++;
            if (this.ﾞॱ == this.ﹶ && ॱˋ() != null) {
                ॱˋ().setResult(-1, null);
                ॱˋ().finish();
            }
        } else {
            evk.ˏ(ॱ(j.ˊ));
        }
        return false;
    }

    public void ॱ(int i, int i2, Intent intent) {
        super.ॱ(i, i2, intent);
    }

    public void onClick(View view) {
        if (view.getId() == e.ʻ || view.getId() == e.ᐝॱ) {
            ˊॱ(true);
            ˎ(this.ꜝ);
            ˊʻ();
        } else if (view.getId() == e.ˋॱ || view.getId() == e.ʼॱ) {
            ˊॱ(false);
            this.ᐝ.setVisibility(8);
            this.ˊ.setVisibility(0);
            ˎ(this.ꜝ);
            ˊʻ();
        } else if (view.getId() == e.ʼ || view.getId() == e.ॱˋ) {
            if (ॱˊ() != null) {
                ˏ(ॱˊ());
            }
        } else if (view.getId() == e.ʾ && ॱˋ() != null) {
            ॱˋ().finish();
        }
    }

    private void ˊॱ(boolean z) {
        for (WishDeleteInfo ˊ : this.ʻˋ) {
            ˊ.ˊ(z);
        }
        if (this.ʻˋ.size() == 0) {
            this.ﾟ.setVisibility(0);
            this.ﹳ.setVisibility(8);
        }
        this.ʹ.notifyDataSetChanged();
    }

    private void ˊʻ() {
        int י = י();
        if (י <= 0) {
            this.ﹺ.setText(ᐝॱ().getString(j.ॱˎ));
            return;
        }
        this.ﹺ.setText(ᐝॱ().getQuantityString(f.ˎ, י, new Object[]{Integer.valueOf(י)}));
    }

    public void ˎ(ToolBarIcon toolBarIcon) {
        try {
            int י = י();
            int i = c.ˎ;
            int color = ᐝॱ().getColor(a.ॱ);
            this.ʻʼ.setEnabled(true);
            toolBarIcon.setEnabled(true);
            if (י <= 0) {
                i = c.ˋ;
                י = ᐝॱ().getColor(a.ˊ);
                toolBarIcon.setEnabled(false);
                this.ʻʼ.setEnabled(false);
                this.ʽʻ.setVisibility(8);
                this.ʴ.setVisibility(0);
                this.ᐝ.setVisibility(8);
                this.ˊ.setVisibility(0);
                ˊ(toolBarIcon, i, י);
                this.ꜞॱ = true;
            } else if (י < this.ʻˋ.size()) {
                this.ʽʻ.setVisibility(8);
                this.ʴ.setVisibility(0);
                this.ᐝ.setVisibility(8);
                this.ˊ.setVisibility(0);
                if (this.ꜞॱ) {
                    ˊ(toolBarIcon, i, color);
                }
                this.ꜞॱ = false;
            } else if (י == this.ʻˋ.size()) {
                this.ʽʻ.setVisibility(0);
                this.ʴ.setVisibility(8);
                this.ᐝ.setVisibility(0);
                this.ˊ.setVisibility(8);
                if (this.ꜞॱ) {
                    ˊ(toolBarIcon, i, color);
                }
                this.ꜞॱ = false;
            }
            this.ʻʻ.setImageResource(i);
        } catch (Exception e) {
            dch.ˎ.ˊ("WishListDeleteFragment", "resetUnintallBtn error:" + e.toString());
        }
    }

    private void ˊ(ToolBarIcon toolBarIcon, int i, int i2) {
        TextView textView = (TextView) toolBarIcon.getChildAt(0);
        int ˋ = epv.ˋ(ContentManager.getInstant().getContext(), 24);
        Drawable drawable = ContentManager.getInstant().getContext().getResources().getDrawable(i);
        drawable.setBounds(0, 0, ˋ, ˋ);
        textView.setCompoundDrawables(null, drawable, null, null);
        textView.setTextColor(i2);
    }

    private void ˏ(Context context) {
        List ٴ = ٴ();
        CharSequence string = context.getResources().getString(j.ᐝॱ, new Object[]{ٴ.get(0)});
        if (ٴ.size() > 1) {
            string = context.getResources().getString(j.ॱˋ, new Object[]{ٴ.get(0)});
        }
        cku ˏ = cku.ˏ(context, cku.class, null, string);
        ˏ.ॱ(-1, ॱ(j.ॱॱ));
        ˏ.ˋ(new ewa(this) {
            final /* synthetic */ WishListDeleteFragment ˎ;

            {
                this.ˎ = r1;
            }

            public void ˏ(Activity activity, DialogInterface dialogInterface, int i) {
                if (i == -1) {
                    this.ˎ.ﾞॱ = 0;
                    this.ˎ.ߺ();
                    for (int i2 = 0; i2 < this.ˎ.ꞌॱ.size(); i2++) {
                        this.ˎ.ʻˊ = ((StringBuffer) this.ˎ.ꞌॱ.get(i2)).toString();
                        this.ˎ.ʼˋ = (String) this.ˎ.ﾟॱ.get(i2);
                        if (this.ˎ.ʻˊ.endsWith(",")) {
                            this.ˎ.ʻˊ = this.ˎ.ʻˊ.substring(0, this.ˎ.ʻˊ.length() - 1);
                            this.ˎ.ʼˋ = this.ˎ.ʼˋ.substring(0, this.ˎ.ʼˋ.length() - 1);
                        }
                        this.ˎ.ʿˊ();
                    }
                    this.ˎ.ﹶ = this.ˎ.ꞌॱ.size();
                    this.ˎ.ꞌॱ.clear();
                    this.ˎ.ﾟॱ.clear();
                }
            }

            public void ˊ(Activity activity, DialogInterface dialogInterface) {
            }
        });
        ˏ.ˎ(context);
    }

    private List<String> ٴ() {
        List<String> arrayList = new ArrayList();
        for (WishDeleteInfo wishDeleteInfo : this.ʻˋ) {
            if (wishDeleteInfo.ᐝ()) {
                arrayList.add(wishDeleteInfo.ˊ());
            }
        }
        return arrayList;
    }

    private int י() {
        int i = 0;
        for (WishDeleteInfo ᐝ : this.ʻˋ) {
            int i2;
            if (ᐝ.ᐝ()) {
                i2 = i + 1;
            } else {
                i2 = i;
            }
            i = i2;
        }
        return i;
    }

    private void ߺ() {
        List arrayList = new ArrayList();
        for (WishDeleteInfo wishDeleteInfo : this.ʻˋ) {
            if (wishDeleteInfo.ᐝ()) {
                arrayList.add(wishDeleteInfo);
            }
        }
        ˎ(arrayList);
    }

    private void ˎ(List<WishDeleteInfo> list) {
        StringBuffer stringBuffer = new StringBuffer();
        List arrayList = new ArrayList();
        StringBuffer stringBuffer2 = new StringBuffer();
        for (int i = 0; i < list.size(); i++) {
            if (i < 300) {
                stringBuffer.append(((WishDeleteInfo) list.get(i)).ˏ());
                stringBuffer.append(",");
                stringBuffer2.append(((WishDeleteInfo) list.get(i)).ˊ());
                stringBuffer2.append(",");
            } else {
                arrayList.add(list.get(i));
            }
        }
        this.ꞌॱ.add(stringBuffer);
        this.ﾟॱ.add(stringBuffer2.toString());
        if (arrayList.size() > 0) {
            ˎ(arrayList);
        }
    }
}
